import hildon
import gtk

class BaseWindow:
    def __init__(self, program, widgets, gtk_window, container, menubar = None):
        # Store member vars.
        self.program = program
        self.widgets = widgets
        
        # Make a hildon window out of the named window (and container).
        gtk_window_widget = self.widgets.get_widget(gtk_window)
        gtk_container_widget = self.widgets.get_widget(container)
        self.window = hildon.Window()
        self.window.set_title(gtk_window_widget.get_title())
        self.program.add_window(self.window)
        self.window.connect('destroy', gtk.main_quit)
        gtk_container_widget.reparent(self.window)

        # Bind to the hardware key event.
        self.window.connect('key-press-event', self.cb_hardware_keys)

        # If the name of a menubar is given Hildonize it as well.
        if menubar != None:
            menubar_widget = widgets.get_widget(menubar)
            new_menubar = gtk.Menu()
            for child in menubar_widget.get_children():
                child.reparent(new_menubar)
            menubar_widget.destroy()
            self.window.set_menu(new_menubar)

    
    def cb_hardware_keys (self, widget, event, *args):
        if event.keyval == gtk.keysyms.Up:
            self.on_up_key_clicked()
        elif event.keyval == gtk.keysyms.Down:
            self.on_down_key_clicked()
        elif event.keyval == gtk.keysyms.Left:
            self.on_left_key_clicked()
        elif event.keyval == gtk.keysyms.Right:
            self.on_right_key_clicked()
        elif event.keyval == gtk.keysyms.F6:
            self.on_fullscreen_key_clicked()
        elif event.keyval == gtk.keysyms.F7:
            self.on_zoom_in_key_clicked()
        elif event.keyval == gtk.keysyms.F8:
            self.on_zoom_out_key_clicked()

    def on_up_key_clicked(self):
        self.up_key_clicked()

    def up_key_clicked(self):
        pass

    def on_down_key_clicked(self):
        self.down_key_clicked()
    
    def down_key_clicked(self):
        pass

    def on_left_key_clicked(self):
        self.left_key_clicked()

    def left_key_clicked(self):
        pass

    def on_right_key_clicked(self):
        self.right_key_clicked()
    
    def right_key_clicked(self):
        pass
    
    def on_fullscreen_key_clicked(self):
        self.fullscreen_key_clicked()
        
    def fullscreen_key_clicked(self):
        pass
    
    def on_zoom_in_key_clicked(self):
        self.zoom_in_key_clicked()
    
    def zoom_in_key_clicked(self):
        pass

    def on_zoom_out_key_clicked(self):
        self.zoom_out_key_clicked()

    def zoom_out_key_clicked(self):
        pass